home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2000 September / maximum-cd-2000-09.iso / Vampire the Masquerade / vampire_demo.exe / Codex.nob / Generator.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-22  |  3.2 KB  |  105 lines

  1. public class Generator extends Codex {
  2.    private String _templateName;
  3.    private float _delay;
  4.    private float _frequency;
  5.    private int _maxThings;
  6.    private int _maxAlive;
  7.    private int numThings;
  8.    private int numAlive;
  9.    private int numFrames;
  10.    private float[] pos;
  11.    private CodexThing generatorThing;
  12.    private CodexThing generatedThing;
  13.    private int generatedGuid;
  14.    public static String[] _params = new String[]{"Template to generate", "Delay;10.0", "Frequency;60.0", "Max Things;20", "Max Alive;0"};
  15.  
  16.    public void beginscene(int clientGuid, int captureID) {
  17.       if (!((double)this._frequency < 0.1)) {
  18.          this.generatorThing = new CodexThing(((Codex)this).GetClassThing());
  19.          if (this.generatorThing != null) {
  20.             this.numFrames = this.generatorThing.GetNumFrames();
  21.             if (this.numFrames != 0) {
  22.                this.pos = this.generatorThing.GetFramePosition(1);
  23.             }
  24.  
  25.             if ((double)this._delay > 0.1) {
  26.                ((Codex)this).SetTimer(this._delay);
  27.             } else {
  28.                ((Codex)this).SetTimer(this._frequency);
  29.             }
  30.          }
  31.  
  32.       }
  33.    }
  34.  
  35.    public void restore(int flags) {
  36.       this._templateName = CodexSequence.RestoreString();
  37.       this._delay = CodexSequence.RestoreFloat();
  38.       this._frequency = CodexSequence.RestoreFloat();
  39.       this._maxThings = CodexSequence.RestoreInt();
  40.       this._maxAlive = CodexSequence.RestoreInt();
  41.       this.numThings = CodexSequence.RestoreInt();
  42.       this.numAlive = CodexSequence.RestoreInt();
  43.    }
  44.  
  45.    public void killed(int guid, int causeID, int captureID) {
  46.       this.numAlive += -1;
  47.       if (this.numAlive < this._maxAlive && (this._maxThings == 0 || this.numThings < this._maxThings)) {
  48.          ((Codex)this).SetTimer(this._frequency);
  49.       }
  50.  
  51.    }
  52.  
  53.    public void save(int flags) {
  54.       CodexSequence.SaveString(this._templateName);
  55.       CodexSequence.SaveFloat(this._delay);
  56.       CodexSequence.SaveFloat(this._frequency);
  57.       CodexSequence.SaveInt(this._maxThings);
  58.       CodexSequence.SaveInt(this._maxAlive);
  59.       CodexSequence.SaveInt(this.numThings);
  60.       CodexSequence.SaveInt(this.numAlive);
  61.    }
  62.  
  63.    public void timer(int timerID, float arg0, float arg1, float arg2, float arg3) {
  64.       try {
  65.          this.generatedGuid = this.generatorThing.SpawnThing(this._templateName);
  66.          this.generatedThing = new CodexThing(this.generatedGuid);
  67.          if (this.generatedThing == null) {
  68.             return;
  69.          }
  70.  
  71.          if (this.numFrames != 0 && Codex.IsActorGuid(this.generatedGuid)) {
  72.             CodexActor actor = new CodexActor(this.generatedGuid);
  73.             actor.SendActorToPos(this.pos, 150.0F);
  74.          }
  75.  
  76.          if (this._maxThings != 0 && ++this.numThings >= this._maxThings) {
  77.             return;
  78.          }
  79.  
  80.          if (this._maxAlive != 0) {
  81.             ((Codex)this).CaptureThing(this.generatedGuid);
  82.             if (++this.numAlive >= this._maxAlive) {
  83.                return;
  84.             }
  85.          }
  86.  
  87.          ((Codex)this).KillTimer();
  88.          ((Codex)this).SetTimer(this._frequency);
  89.       } catch (Exception var8) {
  90.          CodexConsole.PrintException(((Throwable)var8).getMessage() + " in Generator [timer]");
  91.       } catch (Error var9) {
  92.          CodexConsole.PrintError(((Throwable)var9).getMessage() + " in Generator [timer]");
  93.       }
  94.  
  95.    }
  96.  
  97.    public Generator(String templateName, float delay, float frequency, int maxThings, int maxAlive) {
  98.       this._templateName = templateName;
  99.       this._delay = delay;
  100.       this._frequency = frequency;
  101.       this._maxThings = maxThings;
  102.       this._maxAlive = maxAlive;
  103.    }
  104. }
  105.